Skip to content

Skip claim config initialization for organizations#8101

Open
HasiniSama wants to merge 1 commit into
wso2:masterfrom
HasiniSama:claim-init
Open

Skip claim config initialization for organizations#8101
HasiniSama wants to merge 1 commit into
wso2:masterfrom
HasiniSama:claim-init

Conversation

@HasiniSama

@HasiniSama HasiniSama commented May 19, 2026

Copy link
Copy Markdown
Contributor

Proposed changes in this pull request

$subject

Child organization tenants do not maintain their own claim metadata. Their claim dialects, local claims, and external claim mappings are resolved hierarchically from the parent (root) organization via UnifiedClaimMetadataManager and OrgResourceResolverService [1]. Therefore, the per-tenant claim configuration initialization (which seeds rows into IDN_CLAIM_DIALECT / IDN_CLAIM / IDN_CLAIM_MAPPED_ATTRIBUTE for the tenant) must NOT run for child organization tenants.

[1] https://github.com/wso2/carbon-identity-framework/blob/master/components/claim-mgt/org.wso2.carbon.identity.claim.metadata.mgt/src/main/java/org/wso2/carbon/identity/claim/metadata/mgt/UnifiedClaimMetadataManager.java#L93

Comment on lines 64 to +69
try {
/*
* Sub-organization tenants do not maintain their own claim metadata. Therefore, the per-tenant
* claim configuration initialization for the tenant must NOT run for sub-organization tenants.
*/
if (isOrganization(tenantId)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 1

Suggested change
try {
/*
* Sub-organization tenants do not maintain their own claim metadata. Therefore, the per-tenant
* claim configuration initialization for the tenant must NOT run for sub-organization tenants.
*/
if (isOrganization(tenantId)) {
try {
log.debug("Initializing claim metadata store for tenant: " + tenantId);
/*
* Sub-organization tenants do not maintain their own claim metadata. Therefore, the per-tenant
* claim configuration initialization for the tenant must NOT run for sub-organization tenants.
*/
if (isOrganization(tenantId)) {

Comment on lines +69 to +72
if (isOrganization(tenantId)) {
this.tenantId = tenantId;
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 2

Suggested change
if (isOrganization(tenantId)) {
this.tenantId = tenantId;
return;
}
if (isOrganization(tenantId)) {
log.info("Skipping claim metadata initialization for sub-organization tenant: " + tenantId);
this.tenantId = tenantId;
return;
}

@wso2-engineering wso2-engineering Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Agent Log Improvement Checklist

⚠️ Warning: AI-Generated Review Comments

  • The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
  • Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.

✅ Before merging this pull request:

  • Review all AI-generated comments for accuracy and relevance.
  • Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
Comment Accepted (Y/N) Reason
#### Log Improvement Suggestion No: 1
#### Log Improvement Suggestion No: 2

@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR updates DefaultClaimMetadataStore to detect sub-organization tenants and skip claim metadata initialization for those tenants. The constructor now checks if the tenant is a sub-organization using OrganizationManagementUtil, returns early for sub-organization tenants after setting the instance tenantId, and continues with normal initialization for regular tenants. A new private helper method handles organization detection with error handling and fallback.

Changes

Sub-organization tenant detection in claim metadata initialization

Layer / File(s) Summary
Sub-organization detection and early-return in constructor
components/claim-mgt/.../DefaultClaimMetadataStore.java
Imports for OrganizationManagementUtil and OrganizationManagementException added. Constructor logic updated to detect sub-organization tenants and return early after setting tenantId, skipping per-tenant metadata initialization. New private isOrganization(int tenantId) helper method wraps the organization check with exception handling and error logging.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning PR description is minimal and lacks most required sections from the template (Purpose, Goals, Approach, Release note, Documentation, etc.). Complete the PR description by adding Purpose/Goals, Release note, Documentation link, and other relevant sections from the repository template. The context about hierarchical claim resolution is good; expand it into the structured format.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly summarizes the main change: skipping claim configuration initialization for sub-organizations. It is concise, clear, and matches the primary modification in the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@components/claim-mgt/org.wso2.carbon.identity.claim.metadata.mgt/src/main/java/org/wso2/carbon/identity/claim/metadata/mgt/DefaultClaimMetadataStore.java`:
- Around line 95-97: In DefaultClaimMetadataStore (the initialization path that
checks tenant sub-organization status) change the error logging call that
currently uses log.error(..., e) to log only the error message string (remove
the exception object) so the ERROR log contains no stack trace; if you still
need the exception for diagnostics, log the exception at DEBUG/TRACE using the
same message (e.g., use log.debug(...) with the exception) and keep the ERROR
call as a plain message string without the exception parameter.
- Around line 94-99: The catch in DefaultClaimMetadataStore that currently logs
OrganizationManagementException and returns false allows code to proceed with
default claim initialization for tenants when org-check fails; change the catch
to treat failures as "sub-organization" (fail-closed) by returning true (or
rethrowing the exception) so that the default initialization path is not
executed — locate the boolean org-check method (the
isSubOrganization/organization-check call inside DefaultClaimMetadataStore that
catches OrganizationManagementException) and replace the return false in that
catch with return true (or throw a runtime/checked exception) so
sub-organization tenants are not seeded on org-check errors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: ce37eca3-ef6f-4b8c-bf61-4c826b61e660

📥 Commits

Reviewing files that changed from the base of the PR and between 8f097cd and 92c1f3d.

📒 Files selected for processing (1)
  • components/claim-mgt/org.wso2.carbon.identity.claim.metadata.mgt/src/main/java/org/wso2/carbon/identity/claim/metadata/mgt/DefaultClaimMetadataStore.java

Comment on lines +94 to +99
} catch (OrganizationManagementException e) {
log.error("Error while checking whether tenant: " + tenantId +
" is a sub-organization during claim metadata store initialization. " +
"Proceeding with the default claim configuration initialization path.", e);
return false;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fail-open fallback can initialize sub-organization tenants on org-check errors.

When tenant-type detection fails, returning false (Line 98) continues into the default initialization path, which can seed claim metadata for sub-organization tenants.

Suggested fix
 private boolean isOrganization(int tenantId) {
 
     try {
         return OrganizationManagementUtil.isOrganization(tenantId);
     } catch (OrganizationManagementException e) {
-        log.error("Error while checking whether tenant: " + tenantId +
-                " is a sub-organization during claim metadata store initialization. " +
-                "Proceeding with the default claim configuration initialization path.", e);
-        return false;
+        log.error("Error while checking whether tenant: " + tenantId +
+                " is a sub-organization during claim metadata store initialization. " +
+                "Skipping claim configuration initialization for safety.");
+        return true;
     }
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@components/claim-mgt/org.wso2.carbon.identity.claim.metadata.mgt/src/main/java/org/wso2/carbon/identity/claim/metadata/mgt/DefaultClaimMetadataStore.java`
around lines 94 - 99, The catch in DefaultClaimMetadataStore that currently logs
OrganizationManagementException and returns false allows code to proceed with
default claim initialization for tenants when org-check fails; change the catch
to treat failures as "sub-organization" (fail-closed) by returning true (or
rethrowing the exception) so that the default initialization path is not
executed — locate the boolean org-check method (the
isSubOrganization/organization-check call inside DefaultClaimMetadataStore that
catches OrganizationManagementException) and replace the return false in that
catch with return true (or throw a runtime/checked exception) so
sub-organization tenants are not seeded on org-check errors.

Comment on lines +95 to +97
log.error("Error while checking whether tenant: " + tenantId +
" is a sub-organization during claim metadata store initialization. " +
"Proceeding with the default claim configuration initialization path.", e);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

ERROR log should not include the exception object.

This log.error(..., e) pattern violates the repository logging rule for ERROR level in this PR context.

As per coding guidelines, “for ERROR logs, log only the error message (no stack traces/exception objects).”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@components/claim-mgt/org.wso2.carbon.identity.claim.metadata.mgt/src/main/java/org/wso2/carbon/identity/claim/metadata/mgt/DefaultClaimMetadataStore.java`
around lines 95 - 97, In DefaultClaimMetadataStore (the initialization path that
checks tenant sub-organization status) change the error logging call that
currently uses log.error(..., e) to log only the error message string (remove
the exception object) so the ERROR log contains no stack trace; if you still
need the exception for diagnostics, log the exception at DEBUG/TRACE using the
same message (e.g., use log.debug(...) with the exception) and keep the ERROR
call as a plain message string without the exception parameter.

@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented May 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.28%. Comparing base (f36bb4b) to head (dfdd2b9).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
.../claim/metadata/mgt/DefaultClaimMetadataStore.java 0.00% 7 Missing ⚠️

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #8101      +/-   ##
============================================
- Coverage     53.28%   53.28%   -0.01%     
  Complexity    20627    20627              
============================================
  Files          2147     2147              
  Lines        126484   126491       +7     
  Branches      18132    18133       +1     
============================================
- Hits          67403    67395       -8     
- Misses        50866    50881      +15     
  Partials       8215     8215              
Flag Coverage Δ
unit 37.82% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant